# Maintainer: Konstantin Podsvirov <konstantin@podsvirov.su>

_realname=watchfiles
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
pkgver=1.0.5
pkgrel=1
pkgdesc="Simple, modern and high performance file watching and code reload in python (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
msys2_references=(
  'purl: pkg:pypi/watchfiles'
)
msys2_repository_url='https://github.com/samuelcolvin/watchfiles'
url='https://watchfiles.helpmanual.io/'
license=('spdx:MIT')
depends=(
  "${MINGW_PACKAGE_PREFIX}-python"
  "${MINGW_PACKAGE_PREFIX}-python-anyio"
)
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-rust"
  "${MINGW_PACKAGE_PREFIX}-python-maturin"
  "${MINGW_PACKAGE_PREFIX}-python-installer"
)
options=('!strip')
source=("https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz")
sha256sums=('b7529b5dcc114679d43827d8c35a07c493ad6f083633d573d81c660abc5979e9')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"

  "${MINGW_PREFIX}"/bin/cargo fetch --locked
}

build() {
  cd "${srcdir}/${_realname}-${pkgver}"

  export WINAPI_NO_BUNDLED_LIBRARIES=1
  export _PYTHON_HOST_PLATFORM=$(python -c "import sysconfig, sys; sys.stdout.write(sysconfig.get_platform())")
  "${MINGW_PREFIX}"/bin/maturin build --release --strip --locked --all-features
}

check() {
  cd "${srcdir}/${_realname}-${pkgver}"

  "${MINGW_PREFIX}"/bin/cargo test --release --frozen --all-features
}

package() {
  cd "${srcdir}/${_realname}-${pkgver}"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    "${MINGW_PREFIX}"/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" target/wheels/*.whl

  install -vDm 644 LICENSE -t "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/"
  install -vDm 644 README.md -t "${pkgdir}${MINGW_PREFIX}/share/doc/python-${_realname}/"
}
